<?php

namespace App\Providers;

use Illuminate\Support\Facades\Schema;
use Illuminate\Support\ServiceProvider;
use Overtrue\EasySms\EasySms;


class AppServiceProvider extends ServiceProvider
{
    /**
     * Bootstrap any application services.
     *
     * @return void
     */
    public function boot()
    {
        Schema::defaultStringLength(191);
        \Validator::extend('mobile', function ($attribute, $value, $parameters, $validator) {
            return preg_match('/^13\d{9}$|^14\d{9}$|^15\d{9}$|^19\d{9}$|^17\d{9}$|^18\d{9}$/', $value);
        });



    }

    /**
     * Register any application services.
     *
     * @return void
     */
    public function register()
    {
        $this->app->singleton('sms', function () {

            $config = [
                // HTTP 请求的超时时间（秒）
                'timeout' => 5.0,

                // 默认发送配置
                'default' => [
                    // 网关调用策略，默认：顺序调用
                    'strategy' => \Overtrue\EasySms\Strategies\OrderStrategy::class,

                    // 默认可用的发送网关
                    'gateways' => [
                        'aliyun',
                    ],
                ],
                // 可用的网关配置
                'gateways' => [
                    'errorlog' => [
                        'file' => storage_path('/logs/easy-sms.log')
                    ],

                    'aliyun' => [
                        'access_key_id' => config('aliyun_sms.accessKeyId'),
                        'access_key_secret' => config('aliyun_sms.accessKeySecret'),
                        'sign_name' => config('aliyun_sms.signName'),
                    ],
                    //...
                ],
            ];

           return   new EasySms($config);
        });
    }
}
